package proxy

import (
	"strings"

	mysqlquery "github.com/percona/go-mysql/query"
	"github.com/xelabs/go-mysqlstack/sqlparser/depends/query"
	"github.com/xelabs/go-mysqlstack/sqlparser/depends/sqltypes"
	"github.com/xuender/oils/base"
)

func Examine() *sqltypes.Result {
	return &sqltypes.Result{
		Fields:       []*query.Field{{Name: "审核", Type: query.Type_VARCHAR}},
		RowsAffected: 0,
		Rows:         [][]sqltypes.Value{{base.Panic1(sqltypes.NewValue(query.Type_VARCHAR, []byte("进入审核流程")))}},
	}
}

func Error(err error) *sqltypes.Result {
	return &sqltypes.Result{
		Fields:       []*query.Field{{Name: "异常", Type: query.Type_VARCHAR}},
		RowsAffected: 1,
		Rows:         [][]sqltypes.Value{{base.Panic1(sqltypes.NewValue(query.Type_VARCHAR, []byte(err.Error())))}},
	}
}

func Finger(sql string) string {
	return strings.TrimSpace(mysqlquery.Fingerprint(sql))
}
